package com.cn.auth.security.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * describe: 用户登录
 * current user Maochao.zhu
 * current system 2020/6/5
 */
@Controller
public class LoginController implements ErrorController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello SpringSecurity!";
    }


    @GetMapping("/index")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("--------------------index-");
        ModelAndView modelView = new ModelAndView();
        modelView.setViewName("index");
        return modelView;
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }

    /**
     * 去错误界面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "error", method = RequestMethod.GET)
    public ModelAndView error(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelView = new ModelAndView();
        modelView.setViewName("error");
        return modelView;
    }

    /**
     * 没有权限的页面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/authen", method = RequestMethod.GET)
    public ModelAndView authen(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelView = new ModelAndView();
        modelView.setViewName("authen");
        return modelView;
    }
}
